import os
from django.conf import settings
from django.core.wsgi import get_wsgi_application
from flask_openapi3 import OpenAPI
from flask_openapi3 import Info, Tag
import importlib

from manage import DJSettings


class __Settings__:
    """初始化settings"""
    DJSettings(
        INSTALLED_APPS=["demo_api"],
        OPENAPI3_INFO=dict(title="API", version="1.0.0"),
        OPENAPI3_SECURITY_SCHEMES={"basic": {
            "type": "http",
            "scheme": "basic"
        }},
        OPENAPI3_SECURITY=[{"basic": []}]
    ).makemigrations().migrate()


app = OpenAPI(__name__, info=Info(**settings.OPENAPI3_INFO),
              security_schemes=settings.OPENAPI3_SECURITY_SCHEMES)


class __Register__:
    """路由注册"""
    for api_ in settings.INSTALLED_APPS:
        app.register_api(
            getattr(importlib.import_module(f"{api_}.api"), "router"))


if __name__ == "__main__":
    app.run(debug=False, host="0.0.0.0")
